#nullable enable

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using PHMEE.Diagnosis;
using Volo.Abp.Domain.Entities.Auditing;

namespace PHMEE.Entities.Diagnosis;

/// <summary>
/// 报警记录
/// </summary>
public class AlarmRecord : FullAuditedAggregateRoot<Guid>
{
    /// <summary>
    /// 船舶 Id
    /// </summary>
    public Guid VesselId { get; set; }
    
    /// <summary>
    /// 机组 Id
    /// </summary>
    public Guid UnitId { get; set; }

    /// <summary>
    /// 设备 Id，只有当报警测点关联到设备时才有值
    /// </summary>
    public Guid? EquipId { get; set; }

    /// <summary>
    /// 报警测点 Id
    /// </summary>
    public Guid PointId { get; set; }

    /// <summary>
    /// 报警时间，即报警数据的时间戳 Ts
    /// </summary>
    public DateTime AlarmTimeUtc { get; set; }

    /// <summary>
    /// 故障码
    /// </summary>
    public ICollection<string> FaultCodes { get; set; } = new Collection<string>();

    /// <summary>
    /// 诊断结果是否是 no_fault
    /// </summary>
    public bool IsNoFault { get; set; }
    
    /// <summary>
    /// 特征值-报警等级
    /// </summary>
    public Dictionary<AlarmFeatureValue, AlarmLevel> FeatureAlarmLevels { get; set; } = new();

    /// <summary>
    /// 备注
    /// </summary>
    public string? Remark { get; set; }

    /// <summary>
    /// 是否已确认
    /// </summary>
    public bool IsAcked { get; set; }

    /// <summary>
    /// 确认者 Id
    /// </summary>
    public Guid? AckedById { get; set; }

    /// <summary>
    /// 确认者用户名，防止确认者用户被删除，导致无法通过 Id 查询到用户名，所以冗余存储用户名
    /// </summary>
    public string? AckedByUserName { get; set; }

    public AlarmRecord(Guid id, Guid vesselId, Guid unitId, Guid? equipId, Guid pointId, DateTime alarmTimeUtc,
        string[] faultCodes, bool isNoFault, Dictionary<AlarmFeatureValue, AlarmLevel> featureAlarmLevels) : base(id)
    {
        VesselId = vesselId;
        UnitId = unitId;
        EquipId = equipId;
        PointId = pointId;
        AlarmTimeUtc = alarmTimeUtc;
        IsAcked = false;
        FaultCodes = new Collection<string>(faultCodes);
        IsNoFault = isNoFault;
        FeatureAlarmLevels = featureAlarmLevels;
    }

    private AlarmRecord()
    {
    }
}